package com.it9.taotao.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.it9.taotao.base.EasyUIPageDatasBean;
import com.it9.taotao.manager.dao.IGoodsDao;
import com.it9.taotao.manager.pojo.TbItem;
import com.it9.taotao.manager.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    private IGoodsDao goodsDao;

    @Override
    public List<TbItem> listGoods() {
        return goodsDao.listGoods();
    }

    @Override
    public EasyUIPageDatasBean<TbItem> getGoodsPagination(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow, pageSize);

        List<TbItem> tbItemList = goodsDao.listGoods();

        System.out.println(tbItemList.size());

        PageInfo<TbItem> objectPageInfo = new PageInfo<>(tbItemList);

        long total = objectPageInfo.getTotal();
        List<TbItem> list = objectPageInfo.getList();

        EasyUIPageDatasBean<TbItem> objectEasyUIPageDatasBean = new EasyUIPageDatasBean<>();
        objectEasyUIPageDatasBean.setTotal(total);
        objectEasyUIPageDatasBean.setRows(list);


        return objectEasyUIPageDatasBean;
    }
}
